package com.tokenplus.thai.earn.todayEarn.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.tokenplus.thai.R
import com.tokenplus.thai.adata.home.getTransferInEarnList.RevDataGetTransferInEarnList
import com.tokenplus.thai.extend.toFinancePercentString
import com.tokenplus.thai.extend.toFinanceString

class TotalEarnDetailAdapter(private val dataList: List<RevDataGetTransferInEarnList>) :
    RecyclerView.Adapter<TotalEarnDetailAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        var textAdapterTotalEarnDetailDate: TextView =
            view.findViewById(R.id.textAdapterTotalEarnDetailDate)
        var textAdapterTotalEarnDetailEarnAmountValue: TextView =
            view.findViewById(R.id.textAdapterTotalEarnDetailEarnAmountValue)
        var textAdapterTotalEarnDetailTransferAmountValue: TextView =
            view.findViewById(R.id.textAdapterTotalEarnDetailTransferAmountValue)
        var textAdapterTotalEarnDetailEarnRatioValue: TextView =
            view.findViewById(R.id.textAdapterTotalEarnDetailEarnRatioValue)
        var textAdapterTotalEarnDetailStatusValue: TextView =
            view.findViewById(R.id.textAdapterTotalEarnDetailStatusValue)
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int,
    ): ViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.view_adpter_total_earn_detail, parent, false)
        return ViewHolder(view)
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data: RevDataGetTransferInEarnList = dataList[position]
        try {
            holder.textAdapterTotalEarnDetailDate.text = data.createTime
            holder.textAdapterTotalEarnDetailEarnAmountValue.text =
                data.income.toFinanceString() + " USDT"
            holder.textAdapterTotalEarnDetailTransferAmountValue.text =
                data.amount.toFinanceString() + " USDT"
            holder.textAdapterTotalEarnDetailEarnRatioValue.text =
                data.rate.toFinancePercentString()
            holder.textAdapterTotalEarnDetailStatusValue.text = "Success"
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }
}